<?php
namespace app\admin\model;
use think\Model;
use const true;

class RecoveryOrder extends Model
{
    // 表名
    protected $name = 'recovery_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;
    // 追加属性
    protected $append = [
        'typedata_text',
        'ordertime_text',
        'status_text',
        'storagedata_text'
    ];

    public function getPay_typeList()
    {
        return ['0' => __('Pay_type 0'), '1' => __('Pay_type 1')];
    }
    public function getTypedataList()
    {
        return ['0' => __('Typedata 0'), '1' => __('Typedata 1')];
    }
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '6' => __('Status 6')];
    }
    public function getStoragedataList()
    {
        return ['0' => __('Storagedata 0'), '1' => __('Storagedata 1')];
    }
    public function getTypedataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['typedata']) ? $data['typedata'] : '');
        $list = $this->getTypedataList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getOrdertimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ordertime']) ? $data['ordertime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getStoragedataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['storagedata']) ? $data['storagedata'] : '');
        $list = $this->getStoragedataList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    protected function setOrdertimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
    public function user()
    {
        return $this->belongsTo('User', 'order_user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function rider()
    {
        return $this->belongsTo('User', 'rider_user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function useraddress()
    {
        return $this->belongsTo('UserAddress', 'user_address_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
